<?php
/**
 * 0475:执行反馈失败
 * 0479:执行反馈成功
 * 0478:用户名或密码有误
 * 0477:用户名或密码为空
 */
require_once (dirname ( __FILE__ ) . "/../config/config.php");

// 1.验证用户名和密码
$username = $_REQUEST ['username'];

$password = $_REQUEST ['password'];

if ($username == "" || $password == "") {
    
	$error1 = array (
			"message" => "0302" 
	);
	echo json_encode ( $error1 );
} else {
	$sql = "select * from zy_user where user_name = '" . $username . "' and password = '" . $password . "'";
	
	$result = mysql_query ( $sql );
	
	$row = mysql_fetch_array ( $result );
	
	$user_id = $row['user_id'];

	//登录失败
if (empty ( $row )) {
		$error2 = array (
				'message' => '0302' 
		
		);
		echo json_encode ( $error2 );
} else {//登录成功
		// 创建时间
		$create_time = date ( 'y-m-d H:i:s' );
		
		// 获取url参数
		/*
		 * 不支持的文件类型,int类型,0:视频， 1：游戏 2：XXX
		 */
		$type = $_REQUEST ['type']; // 不支持的文件类型,int类型,0:视频， 1：游戏 2：XXX
		/* 获取url参数
		 * 
		 * 不支持的文件类型,int类型,0:视频， 1：游戏 2：XXX
		 * 不支持的视频网站,字符串类型优酷，土豆，爱奇艺
		 * 不支持的视频名称,字符串类型少林寺，avatar，古惑仔
		 * 不支持的平台,int 类型0：PC 1：IOS 2：Android
		 * 不支持的工具, int 类型0：浏览器 1：应用程序（PPStream， 迅雷之类）
		 */
		$type = $_REQUEST ['type']; 
		
		$webname = $_REQUEST ['webname'];
		
		$webvideo = $_REQUEST ['videoname']; 
		
		$platform = $_REQUEST ['platform'];
		
		$tool = $_REQUEST ['tool']; // 不支持的工具, int 类型0：浏览器 1：应用程序（PPStream， 迅雷之类）
		/*
			 执行插入语句
			$sql = "insert into zy_feedback(type,webname,webvideo,platform,tool,create_time,create_user,user_id) values($type,'$webname','$webvideo',$platform,$tool,'$create_time','$username',$user_id)";
			$rs = mysql_query ( $sql );
		*/
		$tool = $_REQUEST ['tool']; 
		/* 执行插入语句
		 *$sql = "insert into zy_feedback(type,webname,webvideo,platform,tool,create_time,create_user,user_id) values($type,'$webname','$webvideo',$platform,$tool,'$create_time','$username',$user_id)";
		 *$rs = mysql_query ( $sql );
         */
		
		//转换成文字
		$Stringtype = GetVideoType($type);
		
		$Stringplatform = GetPlatform($platform);
		
		$Stringtool = GetTool($tool);
		
		//发送邮件至
		$subject = "NetCube | Customer FeedBack";
		
		$message = "Does not support the file type    .$Stringtype.	
		
		Does not support web site   .$webname. 
		
		Does not support video   .$webvideo.
		
		Does not support platform  .$Stringplatform. 
		
		Does not support tool   .$Stringtool.
				";
		
		
		$from = "support@netcube.com.au";
		
		$headers = "From: $from";
		
		mail('support@netcube.com.au', $subject, $message, $headers);
	
		
		//判断邮件是否发送成功
		if (mail('support@netcube.com.au', $subject, $message, $headers)==true) {
		    
			$information = array (
			        
				"message" => "0479"
			);	
		}else {
		    
			$information = array (
			        
				"message" => "0475"
			);			
		}
		echo json_encode ( $information );
		
		
	}
}

/*
 * 获取不支持的文件类型0:视频， 1：游戏  2：其他
 */
function GetVideoType ($type)
{
	 if ($type == 0)	 
		           
			  return 'Video';
		  		  
	 elseif ($type == 1)	
		  	  
			  return 'Game';	
		  	   
	 elseif ($type == 2)	
		  	  
			  return 'Other';
}
/*
 * 获取不支持的平台 ： int 类型，0：PC  1：IOS   2：Android
 */
function GetPlatform ($platform)
{
	 if ($platform == 0)
		      
			  return 'PC';
		  
	 elseif ($platform == 1)
		  
			  return 'IOS';
		  
	 elseif ($platform == 2)
	 
			  return 'Android';
}

/*
 * 获取不支持的工具:int类型，0：浏览器 1：应用程序（PPStream， 迅雷之类）
 */
function GetTool ($tool)
{	
	if ($tool == 0)
		      
			  return 'Browser';
		  
    elseif ($tool == 1)
		  
			  return 'Application Program';
}

/**
 * 输出格式
 * 
 * @param string $type        	
 * @param unknown $result        	
 */
function output_result ($type = "json", $result = array()) 
{
	if ($type == "json") {
	           
		if (empty ( $result )) {
		       
			$message = array (
			        
					"message" => "0475" 
			);
		}else {
		    
			$message = array (
			        
					'message' => '0479'
			);
		}
		
		echo json_encode ( $message );
		exit ();
	}
	

}

?>